<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
    </script>
    <div id="app">
        <p>侦听器</p>
        <p>{{search}}</p>
        <input type="text" v-model="search">

        <ul>
            <li v-for="item in list">
                <p>{{item.count}}</p>
                <button @click="addHandler(item)">+</button>
            </li>
        </ul>
    </div>
    <script src="./vue.global.js"></script>
    <script>
        const {createApp} = Vue;
        createApp({
            data(){
                return {
                    search:'',
                    list:[{count:1},{count:2},{count:3}]
                }
            },
            watch:{
                search:function(){
                    console.log('你正在修改数据')
                },
                // list:function{
                //     console.log('list发生了变化')
                // }
                list:{
                    handler(){
                        console.log('list发生了变化')
                    },
                    deep: true, // 表示开启深度监听
                    immediate:true // 表示初始就执行
                }
            },
            methods:{
                addHandler(item){
                    item.count++;
                }
            }
        }).mount('#app')
    </script>
</body>
</html>